<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\warehouse\model;

use think\Model;

/**
 * 仓库模型
 * @package app\warehouse\model
 */
class WareHouse extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = '__WAREHOUSE_LIST__';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 获取所有仓库
     * @param array $map 条件
     * @param string $order 排序
     * @author 陈梦晨 <2391157750@qq.com>
     * @return mixed
     */
    public static function getAll($map = [], $order = '')
    {
        $data_list = self::where($map)
            ->order($order)
            ->paginate();
        return $data_list;
    }

    /**
     * 获取所有仓库
     * @param array $map 条件
     * @param string $order 排序
     * @author 陈梦晨 <2391157750@qq.com>
     * @return mixed
     */
    public static function getAllList($map = [], $order = '')
    {
        $data_list = self::where($map)->order($order)->column("warehouseid,warehousename");
        return $data_list;
    }

    /**
     * 启用
     * @param string
     * @author 陈梦晨 <2391157750@qq.com>
     * @return bool
     */
    public static function enable($ids = '')
    {
        foreach($ids as $id){
            $result[]=self::where('warehouseid', $id)->setField('status', 1);
        }
        return $result;
    }

    /**
     * 禁用
     * @param string
     * @author 陈梦晨 <2391157750@qq.com>
     * @return bool
     */
    public static function disable($ids = '')
    {
        foreach($ids as $id){
            $result[]=self::where('warehouseid', $id)->setField('status', 0);
        }
        return $result;
        
    }
    public static function del($id){
        return self::update(['warehouseid'=>$id,'isdel'=>1,'delete_time'=>time()]);
    }

    // 一个仓库信息 sky
    public function getOne($wid)
    {
        $wid = intval($wid);
        if($wid==0) return false;
        $data = self::get($wid);
        $data = is_object($data) ? $data->toArray() : array();
        return $data;
    }
}